﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;


namespace CMS.BLL
{
    public class EntryVisa
    {
        #region Common
        public eEntryVisa Data;

        public EntryVisa()
        {
            Data = new eEntryVisa();
        }

        ~EntryVisa()
        {
        }

        public virtual void Dispose()
        {
        }

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cEntryVisa objDAL = new cEntryVisa();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cEntryVisa objDAL = new cEntryVisa();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }
        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cEntryVisa objDAL = new cEntryVisa();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;

                objDAL.Save();
                nResult = objDAL.EntryVisaID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        public int Insert()
        {
            int nResult = 0;
            cEntryVisa objInfor = new cEntryVisa();
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.EntryVisaID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        //Update nhung cai ma eEntryVisa Data dang nam giu thong qua cEntryVisa objInfor
        public int Update(int ID)
        {
            int nResult = 0;
            cEntryVisa objInfor = new cEntryVisa();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        private void MappingData(cEntryVisa objInfor)
        {
            try { objInfor.Address = Data.Address; }
            catch { objInfor.Address =""; }
            
            objInfor.ArrivalDate = Data.ArrivalDate;
            objInfor.BookingDate = Data.BookingDate;
            try { objInfor.ConfirmEmail = Data.ConfirmEmail; }
            catch { objInfor.ConfirmEmail = ""; }

            objInfor.PaymentID = Data.PaymentID;

            objInfor.DoB1 = Data.DoB1;
            objInfor.DoB2 = Data.DoB2;
            objInfor.DoB3 = Data.DoB3;
            objInfor.DoB4 = Data.DoB4;
            objInfor.DoB5 = Data.DoB5;
            objInfor.DoB6 = Data.DoB6;
            objInfor.DoB7 = Data.DoB7;
            objInfor.DoB8 = Data.DoB8;
            try { objInfor.Email = Data.Email; }
            catch { objInfor.Email = ""; }
            objInfor.ExitDate = Data.ExitDate;
            objInfor.ExpiryDate1 = Data.ExpiryDate1;
            objInfor.ExpiryDate2 = Data.ExpiryDate2;
            objInfor.ExpiryDate3 = Data.ExpiryDate3;
            objInfor.ExpiryDate4 = Data.ExpiryDate4;
            objInfor.ExpiryDate5 = Data.ExpiryDate5;
            objInfor.ExpiryDate6 = Data.ExpiryDate6;
            objInfor.ExpiryDate7 = Data.ExpiryDate7;
            objInfor.ExpiryDate8 = Data.ExpiryDate8;
            try { objInfor.Fax = Data.Fax; }
            catch { objInfor.Fax = ""; }

            try { objInfor.FullName = Data.FullName; }
            catch { objInfor.FullName =""; }

            try { objInfor.FullName1 = Data.FullName1; }
            catch { objInfor.FullName1 = ""; }

            try { objInfor.FullName2 = Data.FullName2; }
            catch { objInfor.FullName2 = ""; }

            try { objInfor.FullName3 = Data.FullName3; }
            catch { objInfor.FullName3 = ""; }
            
            try { objInfor.FullName4 = Data.FullName4;}
            catch { objInfor.FullName4 = "";}

            try { objInfor.FullName5 = Data.FullName5; }
            catch { objInfor.FullName5 = ""; }

            try { objInfor.FullName6 = Data.FullName6; }
            catch { objInfor.FullName6 = ""; }

            try { objInfor.FullName7 = Data.FullName7; }
            catch { objInfor.FullName7 = ""; }

            try { objInfor.FullName8 = Data.FullName8; }
            catch { objInfor.FullName8 = ""; }

            objInfor.Gender1 = Data.Gender1;
            objInfor.Gender2 = Data.Gender2;
            objInfor.Gender3 = Data.Gender3;
            objInfor.Gender4 = Data.Gender4;
            objInfor.Gender5 = Data.Gender5;
            objInfor.Gender6 = Data.Gender6;
            objInfor.Gender7 = Data.Gender7;
            objInfor.Gender8 = Data.Gender8;
            try { objInfor.Nationality1 = Data.Nationality1; }
            catch { objInfor.Nationality1 = ""; }

            try { objInfor.Nationality2 = Data.Nationality2; }
            catch { objInfor.Nationality2 = ""; }

            try { objInfor.Nationality3 = Data.Nationality3; }
            catch { objInfor.Nationality3 = ""; }

            try { objInfor.Nationality4 = Data.Nationality4; }
            catch { objInfor.Nationality4 = ""; }

            try { objInfor.Nationality5 = Data.Nationality5; }
            catch { objInfor.Nationality5 = ""; }

            try { objInfor.Nationality6 = Data.Nationality6; }
            catch { objInfor.Nationality6 = ""; }

            try { objInfor.Nationality7 = Data.Nationality7; }
            catch { objInfor.Nationality7 = ""; }

            try { objInfor.Nationality8 = Data.Nationality8; }
            catch { objInfor.Nationality8 = ""; }

            try { objInfor.NumberOfEntry = Data.NumberOfEntry; }
            catch { objInfor.NumberOfEntry = ""; }

            try { objInfor.OtherRequest = Data.OtherRequest; }
            catch { objInfor.OtherRequest = ""; }

            try { objInfor.PassportNo1 = Data.PassportNo1; }
            catch { objInfor.PassportNo1 = ""; }

            try { objInfor.PassportNo2 = Data.PassportNo2; }
            catch { objInfor.PassportNo2 = ""; }

            try { objInfor.PassportNo3 = Data.PassportNo3; }
            catch { objInfor.PassportNo3 = ""; }

            try { objInfor.PassportNo4 = Data.PassportNo4; }
            catch { objInfor.PassportNo4 = ""; }

            try { objInfor.PassportNo5 = Data.PassportNo5; }
            catch { objInfor.PassportNo5 = ""; }

            try { objInfor.PassportNo6 = Data.PassportNo6; }
            catch { objInfor.PassportNo6 = ""; }

            try { objInfor.PassportNo7 = Data.PassportNo7; }
            catch { objInfor.PassportNo7 = ""; }

            try { objInfor.PassportNo8 = Data.PassportNo8; }
            catch { objInfor.PassportNo8 = ""; }

            
            try { objInfor.PortOfArrival = Data.PortOfArrival; }
            catch { objInfor.PortOfArrival = ""; }

            try { objInfor.PurposeOfEntry = Data.PurposeOfEntry; }
            catch { objInfor.PurposeOfEntry = ""; }
            
            objInfor.Status = Data.Status;
            try { objInfor.Tel = Data.Tel; }
            catch { objInfor.Tel = ""; }

            try { objInfor.VisaPeriod = Data.VisaPeriod; }
            catch { objInfor.VisaPeriod = ""; }
            
        }
        private void ConvertData(cEntryVisa objInfor)
        {
            Data.Address = objInfor.Address;
            Data.ArrivalDate = objInfor.ArrivalDate;
            Data.BookingDate = objInfor.BookingDate;
            Data.ConfirmEmail = objInfor.ConfirmEmail;
            Data.DoB1 = objInfor.DoB1;
            Data.DoB2 = objInfor.DoB2;
            Data.DoB3 = objInfor.DoB3;
            Data.DoB4 = objInfor.DoB4;
            Data.DoB5 = objInfor.DoB5;
            Data.DoB6 = objInfor.DoB6;
            Data.DoB7 = objInfor.DoB7;
            Data.DoB8 = objInfor.DoB8;
            Data.Email = objInfor.Email;
            Data.ExitDate = objInfor.ExitDate;
            Data.ExpiryDate1 = objInfor.ExpiryDate1;
            Data.ExpiryDate2 = objInfor.ExpiryDate2;
            Data.ExpiryDate3 = objInfor.ExpiryDate3;
            Data.ExpiryDate4 = objInfor.ExpiryDate4;
            Data.ExpiryDate5 = objInfor.ExpiryDate5;
            Data.ExpiryDate6 = objInfor.ExpiryDate6;
            Data.ExpiryDate7 = objInfor.ExpiryDate7;
            Data.ExpiryDate8 = objInfor.ExpiryDate8;
            Data.Fax = objInfor.Fax;
            Data.FullName = objInfor.FullName;
            Data.FullName1 = objInfor.FullName1;
            Data.FullName2 = objInfor.FullName2;
            Data.FullName3 = objInfor.FullName3;
            Data.FullName4 = objInfor.FullName4;
            Data.FullName5 = objInfor.FullName5;
            Data.FullName6 = objInfor.FullName6;
            Data.FullName7 = objInfor.FullName7;
            Data.FullName8 = objInfor.FullName8;

            Data.Gender1 = objInfor.Gender1;
            Data.Gender2 = objInfor.Gender2;
            Data.Gender3 = objInfor.Gender3;
            Data.Gender4 = objInfor.Gender4;
            Data.Gender5 = objInfor.Gender5;
            Data.Gender6 = objInfor.Gender6;
            Data.Gender7 = objInfor.Gender7;
            Data.Gender8 = objInfor.Gender8;

            Data.Nationality1 = objInfor.Nationality1;
            Data.Nationality2 = objInfor.Nationality2;
            Data.Nationality3 = objInfor.Nationality3;
            Data.Nationality4 = objInfor.Nationality4;
            Data.Nationality5 = objInfor.Nationality5;
            Data.Nationality6 = objInfor.Nationality6;
            Data.Nationality7 = objInfor.Nationality7;
            Data.Nationality8 = objInfor.Nationality8;

            Data.NumberOfEntry = objInfor.NumberOfEntry;
            Data.OtherRequest = objInfor.OtherRequest;
            Data.PassportNo1 = objInfor.PassportNo1;
            Data.PassportNo2 = objInfor.PassportNo2;
            Data.PassportNo3 = objInfor.PassportNo3;
            Data.PassportNo4 = objInfor.PassportNo4;
            Data.PassportNo5 = objInfor.PassportNo5;
            Data.PassportNo6 = objInfor.PassportNo6;
            Data.PassportNo7 = objInfor.PassportNo7;
            Data.PassportNo8 = objInfor.PassportNo8;

            Data.PaymentID = objInfor.PaymentID;
            Data.PortOfArrival = objInfor.PortOfArrival;
            Data.PurposeOfEntry = objInfor.PurposeOfEntry;
            Data.Status = objInfor.Status;
            Data.Tel = objInfor.Tel;
            Data.VisaPeriod = objInfor.VisaPeriod;
            
        }
        public DataTable GetALL()
        {
            DataTable tbResult = new DataTable();
            cEntryVisa objDAL = new cEntryVisa();
            tbResult = objDAL.GetALL();
            return tbResult;
        }
        public DataTable Search(int ItemID, int ItemView, int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cEntryVisa objDAL = new cEntryVisa();
            tbResult = objDAL.Search(ItemID, ItemView, PageIndex, PageSize, ref PageCount);
            return tbResult;
        }
        #endregion
    }
}
